package de.dqi.pong.menu;

import javax.swing.JFrame;

import de.dqi.pong.engine.Tick;

/**
 * TODO Frame - finish class definition
 * <hr>
 * 
 * <hr><dl><dt>
 * Summary: </dt><br><dd>
 *  
 * </dd><br><dt>
 * Author: </dt><br><dd>
 *  Melina
 * </dd></dl>
 */
public class Frame
		extends JFrame {
	
	
	private static final long	serialVersionUID	= -4421585010809222177L;
	public static final int		STARTGUI			= 0;
	public static final int		PLAYMENU			= 1;
	public static final int		OPTIONMENUE			= 2;
	public static final int		ENDMENU				= 3;
	public static final int		GAME				= 10;
	private StartGui			startGui;
	private EndMenu				endMenu;
	private OptionMenu			optionMenue;
	private PlayMenu			playMenu;
	private static Frame		instance;
	
	Tick						game;
	
	
	public static Frame getInstance() {
		if (instance == null) {
			instance = new Frame();
		}
		return instance;
	}
	
	private Frame() {
		startGui = new StartGui();
		endMenu = new EndMenu(startGui);
		optionMenue = new OptionMenu(startGui);
		playMenu = new PlayMenu(startGui);
		setContentPane(startGui);
		setBounds(535, 190, 250 + 6, 300 + 29);
		setTitle("PONG");
		setLayout(null);
		setResizable(false);
		
		setVisible(true);
		setDefaultCloseOperation(EXIT_ON_CLOSE);
		
		game = new Tick();
	}
	
	
	public void switchPanel(int panelNumber) {
		switch (panelNumber) {
		case (-1): {
			this.dispose();
			System.exit(0);
			break;
		}
		case (STARTGUI): {
			setContentPane(((MenuPanel) getContentPane()).getParentPanel());
			setSize(getContentPane().getWidth() + 6, getContentPane().getHeight() + 29);
			break;
		}
		case (ENDMENU): {
			setSize(endMenu.getWidth() + 6, endMenu.getHeight() + 29);
			endMenu.setWinner(game.getWinner());
			endMenu.setScore(game.getScore());
			setContentPane(endMenu);
			break;
		}
		case (OPTIONMENUE): {
			setSize(optionMenue.getWidth() + 6, optionMenue.getHeight() + 29);
			setContentPane(optionMenue);
			break;
		}
		
		case (PLAYMENU): {
			setSize(playMenu.getWidth() + 6, playMenu.getHeight() + 29);
			setContentPane(playMenu);
			break;
		}
		case (GAME): {
			setSize(850 + 6, 700 + 29);
			Thread gameThread = new Thread(game, "Tick");
			gameThread.start();
			setContentPane(game.getRender().getDisplay());
			break;
		}
		
		}
	}
}
